package itdep.common.context.spring;

import org.springframework.security.acls.model.*;
import org.springframework.util.Assert;

import java.util.Collections;
import java.util.List;

/**
 * @author Ivan Khalopik
 * @version $Revision: 4 $ $Date: 2010-06-10 13:13:16 +0000 (Thu, 10 Jun 2010) $
 */
public class DynamicAcl implements Acl {
	private final ObjectIdentity objectIdentity;
	private final SecurityChecker securityChecker;

	public DynamicAcl(final ObjectIdentity objectIdentity, final SecurityChecker securityChecker) {
		this.objectIdentity = objectIdentity;
		this.securityChecker = securityChecker;
	}

	public List<AccessControlEntry> getEntries() {
		return Collections.emptyList();
	}

	public ObjectIdentity getObjectIdentity() {
		return objectIdentity;
	}

	public Sid getOwner() {
		return null;  //todo: default method body
	}

	public Acl getParentAcl() {
		return null;  //todo: default method body
	}

	public boolean isEntriesInheriting() {
		return false;  //todo: default method body
	}

	@Override
	public boolean isGranted(final List<Permission> permissions, final List<Sid> sids, final boolean administrativeMode) throws NotFoundException, UnloadedSidException {
		Assert.notEmpty(permissions, "Permissions required");
		Assert.notEmpty(sids, "SIDs required");
		return securityChecker.check(this, sids, permissions);
	}

	@Override
	public boolean isSidLoaded(final List<Sid> sids) {
		return true;
	}
}
